package com.ruoyi.student.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.student.domain.Student;
import com.ruoyi.student.dto.StudentTrackDto;
import com.ruoyi.student.mapper.StudentMapper;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.student.mapper.StudenttracklogMapper;
import com.ruoyi.student.domain.Studenttracklog;
import com.ruoyi.student.service.IStudenttracklogService;

import javax.security.auth.login.LoginContext;
import javax.servlet.http.HttpServletRequest;

/**
 * 跟踪表Service业务层处理
 * 
 * @author hoyo
 * @date 2022-12-29
 */
@Service
public class StudenttracklogServiceImpl implements IStudenttracklogService 
{
    @Autowired
    private StudenttracklogMapper studenttracklogMapper;
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 查询跟踪表
     * 
     * @param id 跟踪表主键
     * @return 跟踪表
     */
    @Override
    public Studenttracklog selectStudenttracklogById(Long id)
    {
        return studenttracklogMapper.selectStudenttracklogById(id);
    }

    /**
     * 查询跟踪表列表
     * 
     * @param studenttracklog 跟踪表
     * @return 跟踪表
     */
    @Override
    public List<Studenttracklog> selectStudenttracklogList(Studenttracklog studenttracklog)
    {
        return studenttracklogMapper.selectStudenttracklogList(studenttracklog);
    }

    /**
     * 新增跟踪表
     * 
     * @param studenttracklog 跟踪表
     * @return 结果
     */
    @Override
    public int insertStudenttracklog(Studenttracklog studenttracklog)
    {
        return studenttracklogMapper.insertStudenttracklog(studenttracklog);
    }

    /**
     * 修改跟踪表
     * 
     * @param studenttracklog 跟踪表
     * @return 结果
     */
    @Override
    public int updateStudenttracklog(Studenttracklog studenttracklog)
    {
        return studenttracklogMapper.updateStudenttracklog(studenttracklog);
    }

    /**
     * 批量删除跟踪表
     * 
     * @param ids 需要删除的跟踪表主键
     * @return 结果
     */
    @Override
    public int deleteStudenttracklogByIds(Long[] ids)
    {
        return studenttracklogMapper.deleteStudenttracklogByIds(ids);
    }

    /**
     * 删除跟踪表信息
     * 
     * @param id 跟踪表主键
     * @return 结果
     */
    @Override
    public int deleteStudenttracklogById(Long id)
    {
        return studenttracklogMapper.deleteStudenttracklogById(id);
    }

    /**
     * 添加跟踪表
     * @param studentTrackDto
     */
    @Override
    public void saveStudenttrack(StudentTrackDto studentTrackDto)
    {
       Long id = studentTrackDto.getStuSn();
    /*   Studenttracklog studenttracklog1 = studenttracklogMapper.selectStudenttracklogByStusn(id);
        if (studenttracklog1!=null){
            throw new RuntimeException("该学员已经在跟踪中");
        }*/
        //获取当前用户信息
        LoginUser loginUser = SecurityUtils.getLoginUser();
        //将当前用户信息存入
        studentTrackDto.setTeacherName(loginUser.getUsername());
        //存入数据
        Studenttracklog studenttracklog = new Studenttracklog();
        studenttracklog.setStuSn(studentTrackDto.getStuSn());
        studenttracklog.setProblem(studentTrackDto.getProblem());
        studenttracklog.setDeductMarks(studentTrackDto.getDeductMarks());
        studenttracklog.setOccurrenceTime(studentTrackDto.getOccurrenceTime());
        studenttracklog.setTime(new Date());
        studenttracklog.setProblemDescription(studentTrackDto.getProblemDescription());
        studenttracklog.setTeacherName(studentTrackDto.getTeacherName());
        studenttracklogMapper.insertStudenttracklog(studenttracklog);
    }

    /**
     * 查询跟踪表
     * @param id
     * @return
     */
    @Override
    public List<Studenttracklog> getStudenttrackstuSn(Long id) {

        return studenttracklogMapper.selectStudenttracklogByStusn(id);
    }
}
